From f98153b45cba661670041318bcfd4767890a57d0 Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Fri, 17 Sep 2004 16:32:52 +0000 Subject: [PATCH] Standardize default option values, add 'exit' routine to I/O vectors --- gpsbabel/arcdist.c | 11 +++--- gpsbabel/brauniger_iq.c | 3 +- gpsbabel/cetus.c | 5 ++- gpsbabel/defs.h | 3 ++ gpsbabel/duplicate.c | 10 ++--- gpsbabel/easygps.c | 6 ++- gpsbabel/filter_vecs.c | 24 +++++++++++- gpsbabel/garmin.c | 18 +++++---- gpsbabel/geo.c | 7 ++-- gpsbabel/geoniche.c | 5 ++- gpsbabel/gpilots.c | 5 ++- gpsbabel/gpspilot.c | 5 ++- gpsbabel/gpx.c | 18 ++++++--- gpsbabel/hsa_ndv.c | 4 +- gpsbabel/html.c | 9 +++-- gpsbabel/igc.c | 6 ++- gpsbabel/magproto.c | 17 +++++---- gpsbabel/mapsource.c | 28 +++++++++----- gpsbabel/navicache.c | 7 ++-- gpsbabel/netstumbler.c | 33 ++++++++-------- gpsbabel/ozi.c | 19 +++++----- gpsbabel/palmdoc.c | 15 +++++--- gpsbabel/pcx.c | 21 +++------- gpsbabel/polygon.c | 6 +-- gpsbabel/position.c | 30 ++++++++------- gpsbabel/psitrex.c | 6 ++- gpsbabel/quovadis.c | 5 ++- gpsbabel/reverse_route.c | 2 +- gpsbabel/saroute.c | 6 ++- gpsbabel/smplrout.c | 4 +- gpsbabel/sort.c | 11 ++++-- gpsbabel/stackfilter.c | 25 +++++++----- gpsbabel/text.c | 10 +++-- gpsbabel/tiger.c | 82 ++++++++++++++++------------------------ gpsbabel/vecs.c | 30 ++++++++++++++- gpsbabel/xcsv.c | 32 ++++++++-------- 36 files changed, 303 insertions(+), 225 deletions(-) diff --git a/gpsbabel/arcdist.c b/gpsbabel/arcdist.c index 7f49dffc6..3fc13459a 100644 --- a/gpsbabel/arcdist.c +++ b/gpsbabel/arcdist.c @@ -39,13 +39,14 @@ typedef struct { static arglist_t arcdist_args[] = { {"file", &arcfileopt, "File containing vertices of arc", - ARGTYPE_FILE | ARGTYPE_REQUIRED}, + NULL, ARGTYPE_FILE | ARGTYPE_REQUIRED}, {"distance", &distopt, "Maximum distance from arc", - ARGTYPE_FLOAT | ARGTYPE_REQUIRED}, - {"exclude", &exclopt, "Exclude points close to the arc", ARGTYPE_BOOL}, - {"points", &ptsopt, "Use distance from vertices not lines", + NULL, ARGTYPE_FLOAT | ARGTYPE_REQUIRED}, + {"exclude", &exclopt, "Exclude points close to the arc", NULL, ARGTYPE_BOOL}, - {0, 0, 0, 0} + {"points", &ptsopt, "Use distance from vertices not lines", + NULL, ARGTYPE_BOOL}, + {0, 0, 0, 0, 0} }; #define BADVAL 999999 diff --git a/gpsbabel/brauniger_iq.c b/gpsbabel/brauniger_iq.c index 3ab4a2fe3..2d06c5753 100644 --- a/gpsbabel/brauniger_iq.c +++ b/gpsbabel/brauniger_iq.c @@ -263,7 +263,7 @@ static void data_read(void) } static arglist_t brauniger_iq_args[] = { - {0, 0, 0, 0} + {0, 0, 0, 0, 0} }; ff_vecs_t brauniger_iq_vecs = { @@ -274,5 +274,6 @@ ff_vecs_t brauniger_iq_vecs = { NULL, data_read, NULL, + NULL, brauniger_iq_args }; diff --git a/gpsbabel/cetus.c b/gpsbabel/cetus.c index fd17a0918..a85c9d487 100644 --- a/gpsbabel/cetus.c +++ b/gpsbabel/cetus.c @@ -100,9 +100,9 @@ static char *appendicon = NULL; static arglist_t cetus_args[] = { - {"dbname", &dbname, "Database name", ARGTYPE_STRING }, + {"dbname", &dbname, "Database name", NULL, ARGTYPE_STRING }, {"appendicon", &appendicon, "Append icon_descr to description.", - ARGTYPE_BOOL }, + NULL, ARGTYPE_BOOL }, {0, 0, 0, 0 } }; @@ -422,5 +422,6 @@ ff_vecs_t cetus_vecs = { wr_deinit, data_read, data_write, + NULL, cetus_args, }; diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index f43d03e89..807d3dc82 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -234,6 +234,7 @@ typedef void (*ff_init) (char const *); typedef void (*ff_deinit) (void); typedef void (*ff_read) (void); typedef void (*ff_write) (void); +typedef void (*ff_exit) (void); #ifndef DEBUG_MEM char * get_option(const char *iarglist, const char *argname); @@ -332,6 +333,7 @@ typedef struct arglist { char *argstring; char **argval; char *helpstring; + char *defaultvalue; long argtype; } arglist_t; @@ -352,6 +354,7 @@ typedef struct ff_vecs { ff_deinit wr_deinit; ff_read read; ff_write write; + ff_exit exit; arglist_t *args; } ff_vecs_t; diff --git a/gpsbabel/duplicate.c b/gpsbabel/duplicate.c index afeed3603..2d3b57464 100644 --- a/gpsbabel/duplicate.c +++ b/gpsbabel/duplicate.c @@ -31,14 +31,14 @@ static char *correct_coords = NULL; static arglist_t dup_args[] = { {"shortname", &snopt, "Suppress duplicate waypoints based on name", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"location", &lcopt, "Suppress duplicate waypoint based on coords", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"all", &purge_duplicates, "Suppress all instances of duplicates", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"correct", &correct_coords, "Use coords from duplicate points", - ARGTYPE_BOOL}, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL}, + {0, 0, 0, 0, 0} }; diff --git a/gpsbabel/easygps.c b/gpsbabel/easygps.c index 45e740017..827d2057f 100644 --- a/gpsbabel/easygps.c +++ b/gpsbabel/easygps.c @@ -25,13 +25,14 @@ static FILE *file_in; static FILE *file_out; static void *mkshort_handle; -static char *deficon = "Waypoint"; +static char *deficon = NULL; #define MYNAME "EasyGPS" static arglist_t easygps_args[] = { -/* {"deficon", &deficon, "Default icon name", ARGTYPE_STRING}, */ +/* {"deficon", &deficon, "Default icon name", "Waypoint", + ARGTYPE_STRING}, */ {0, 0, 0, 0 } }; @@ -268,5 +269,6 @@ ff_vecs_t easygps_vecs = { wr_deinit, data_read, data_write, + NULL, easygps_args }; diff --git a/gpsbabel/filter_vecs.c b/gpsbabel/filter_vecs.c index 1306bb832..aab1af133 100644 --- a/gpsbabel/filter_vecs.c +++ b/gpsbabel/filter_vecs.c @@ -114,11 +114,33 @@ find_filter_vec(char *const vecname, char **opts) if (vec->vec->args) { for (ap = vec->vec->args; ap->argstring; ap++){ - *ap->argval = get_option(*opts, ap->argstring); + char *opt = get_option(*opts, + ap->argstring); + if ( opts ) { + *ap->argval = opt; + } + else if ( ap->defaultvalue ) { + *ap->argval = xstrdup( + ap->defaultvalue); + } + else { + *ap->argval = NULL; + } } } } else { *opts = NULL; + if (vec->vec->args) { + for (ap = vec->vec->args; ap->argstring; ap++){ + if ( ap->defaultvalue ) { + *ap->argval = xstrdup( + ap->defaultvalue); + } + else { + *ap->argval = NULL; + } + } + } } xfree(v); diff --git a/gpsbabel/garmin.c b/gpsbabel/garmin.c index b2c22b026..898fc59ac 100644 --- a/gpsbabel/garmin.c +++ b/gpsbabel/garmin.c @@ -32,20 +32,21 @@ static GPS_PWay *tx_routelist; static GPS_PWay *cur_tx_routelist_entry; static GPS_PTrack *tx_tracklist; static GPS_PTrack *cur_tx_tracklist_entry; -static char *getposn; -static char *poweroff; -static char *snlen; -static char *snwhiteopt; +static char *getposn = NULL; +static char *poweroff = NULL; +static char *snlen = NULL; +static char *snwhiteopt = NULL; static arglist_t garmin_args[] = { - { "snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT }, + { "snlen", &snlen, "Length of generated shortnames", NULL, + ARGTYPE_INT }, { "snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, { "get_posn", &getposn, "Return current position as a waypoint", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, { "power_off", &poweroff, "Command unit to power itself down", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, { 0, 0, 0, 0} }; @@ -624,6 +625,7 @@ ff_vecs_t garmin_vecs = { rw_deinit, data_read, data_write, + NULL, garmin_args }; diff --git a/gpsbabel/geo.c b/gpsbabel/geo.c index ceb14b242..9e8eeca10 100644 --- a/gpsbabel/geo.c +++ b/gpsbabel/geo.c @@ -29,7 +29,7 @@ static int in_type; static int in_cdata; static char *cdatastr; static char *typestr; -static char *deficon; +static char *deficon = NULL; static waypoint *wpt_tmp; @@ -38,8 +38,8 @@ FILE *ofd; static arglist_t geo_args[] = { - {"deficon", &deficon, "Default icon name", ARGTYPE_STRING }, - {0, 0, 0, 0} + {"deficon", &deficon, "Default icon name", NULL, ARGTYPE_STRING }, + {0, 0, 0, 0, 0} }; #define MYNAME "geo" @@ -293,5 +293,6 @@ ff_vecs_t geo_vecs = { geo_wr_deinit, geo_read, geo_write, + NULL, geo_args }; diff --git a/gpsbabel/geoniche.c b/gpsbabel/geoniche.c index 4302ff279..60f955c70 100644 --- a/gpsbabel/geoniche.c +++ b/gpsbabel/geoniche.c @@ -40,9 +40,9 @@ static char *Arg_category = NULL; static arglist_t Args[] = { {"dbname", &Arg_dbname, - "Database name (filename)", ARGTYPE_STRING }, + "Database name (filename)", NULL, ARGTYPE_STRING }, {"category", &Arg_category, - "Category name (Cache)", ARGTYPE_STRING }, + "Category name (Cache)", NULL, ARGTYPE_STRING }, {0, 0, 0, 0 } }; @@ -532,5 +532,6 @@ ff_vecs_t geoniche_vecs = wr_deinit, data_read, data_write, + NULL, Args }; diff --git a/gpsbabel/gpilots.c b/gpsbabel/gpilots.c index 27824e5e6..0a95644fb 100644 --- a/gpsbabel/gpilots.c +++ b/gpsbabel/gpilots.c @@ -160,8 +160,8 @@ static char *dbname = NULL; static arglist_t my_args[] = { - {"dbname", &dbname, "Database name", ARGTYPE_STRING}, - {0, 0, 0, 0} + {"dbname", &dbname, "Database name", NULL, ARGTYPE_STRING}, + {0, 0, 0, 0, 0} }; static void @@ -414,5 +414,6 @@ ff_vecs_t gpilots_vecs = { wr_deinit, data_read, data_write, + NULL, my_args }; diff --git a/gpsbabel/gpspilot.c b/gpsbabel/gpspilot.c index 5edc21513..7863af855 100644 --- a/gpsbabel/gpspilot.c +++ b/gpsbabel/gpspilot.c @@ -54,8 +54,8 @@ static char *dbname = NULL; static arglist_t gpspilot_args[] = { - {"dbname", &dbname, "Database name", ARGTYPE_STRING}, - {0, 0, 0, 0} + {"dbname", &dbname, "Database name", NULL, ARGTYPE_STRING}, + {0, 0, 0, 0, 0} }; static void @@ -253,5 +253,6 @@ ff_vecs_t gpspilot_vecs = { wr_deinit, data_read, data_write, + NULL, gpspilot_args }; diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index b1caa107c..7b9830da3 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -1288,13 +1288,18 @@ static arglist_t gpx_args[] = { { "gsshortnames", &gsshortnames, "Prefer shorter descriptions from Groundspeak files", - ARGTYPE_BOOL }, - { "snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT }, + NULL, ARGTYPE_BOOL }, + { "snlen", &snlen, "Length of generated shortnames", + NULL, ARGTYPE_INT }, { "suppresswhite", &suppresswhite, - "Suppress whitespace in generated shortnames", ARGTYPE_BOOL }, - { "logpoint", &opt_logpoint, "Create waypoints from geocache log entries", ARGTYPE_BOOL }, - { "urlbase", &urlbase, "Base URL for link tag in output", ARGTYPE_STRING}, - { 0, 0, 0, 0 } + "Suppress whitespace in generated shortnames", + NULL, ARGTYPE_BOOL }, + { "logpoint", &opt_logpoint, + "Create waypoints from geocache log entries", + NULL, ARGTYPE_BOOL }, + { "urlbase", &urlbase, "Base URL for link tag in output", + NULL, ARGTYPE_STRING}, + { 0, 0, 0, 0, 0 } }; ff_vecs_t gpx_vecs = { @@ -1305,5 +1310,6 @@ ff_vecs_t gpx_vecs = { gpx_wr_deinit, gpx_read, gpx_write, + NULL, gpx_args, }; diff --git a/gpsbabel/hsa_ndv.c b/gpsbabel/hsa_ndv.c index 7e37a67d2..7cfa2c66d 100644 --- a/gpsbabel/hsa_ndv.c +++ b/gpsbabel/hsa_ndv.c @@ -42,8 +42,7 @@ FILE *ofd; static arglist_t hsa_ndv_args[] = { -// {"deficon", &deficon, "Default icon name", ARGTYPE_STRING }, - {0, 0, 0, 0} + {0, 0, 0, 0, 0} }; #define MYNAME "HsaNdv" @@ -352,6 +351,7 @@ ff_vecs_t HsaEndeavourNavigator_vecs = { hsa_ndv_wr_deinit, hsa_ndv_read, hsa_ndv_write, + NULL, hsa_ndv_args }; diff --git a/gpsbabel/html.c b/gpsbabel/html.c index a3bffbe27..bc00b547e 100644 --- a/gpsbabel/html.c +++ b/gpsbabel/html.c @@ -36,12 +36,12 @@ static char *includelogs = NULL; static arglist_t html_args[] = { { "stylesheet", &stylesheet, - "Path to HTML style sheet", ARGTYPE_STRING }, + "Path to HTML style sheet", NULL, ARGTYPE_STRING }, { "encrypt", &encrypt, - "Encrypt hints using ROT13", ARGTYPE_BOOL }, + "Encrypt hints using ROT13", NULL, ARGTYPE_BOOL }, { "logs", &includelogs, - "Include groundspeak logs if present", ARGTYPE_BOOL }, - {0, 0, 0, 0} + "Include groundspeak logs if present", NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; @@ -260,5 +260,6 @@ ff_vecs_t html_vecs = { wr_deinit, NULL, data_write, + NULL, html_args }; diff --git a/gpsbabel/igc.c b/gpsbabel/igc.c index ef2af2349..5ccbfb0c6 100644 --- a/gpsbabel/igc.c +++ b/gpsbabel/igc.c @@ -887,8 +887,9 @@ static void data_write(void) static arglist_t igc_args[] = { {"timeadj", &timeadj, - "(integer sec or 'auto') Barograph to GPS time diff", ARGTYPE_STRING}, - {0, 0, 0, 0} + "(integer sec or 'auto') Barograph to GPS time diff", + NULL, ARGTYPE_STRING}, + {0, 0, 0, 0, 0} }; ff_vecs_t igc_vecs = { @@ -899,5 +900,6 @@ ff_vecs_t igc_vecs = { wr_deinit, data_read, data_write, + NULL, igc_args }; diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 4c9406467..87424e204 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -709,18 +709,19 @@ termwrite(char *obuf, int size) */ static arglist_t mag_sargs[] = { - {"baud", &bs, "Numeric value of bitrate (baud=4800)", ARGTYPE_INT }, + {"baud", &bs, "Numeric value of bitrate (baud=4800)", NULL, + ARGTYPE_INT }, {"noack", &noack, "Suppress use of handshaking in name of speed", - ARGTYPE_BOOL}, - {"deficon", &deficon, "Default icon name", ARGTYPE_STRING }, - {"nukewpt", &nukewpt, "Delete all waypoints", ARGTYPE_BOOL }, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL}, + {"deficon", &deficon, "Default icon name", NULL, ARGTYPE_STRING }, + {"nukewpt", &nukewpt, "Delete all waypoints", NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; static arglist_t mag_fargs[] = { - {"deficon", &deficon, "Default icon name", ARGTYPE_STRING }, - {0, 0, 0, 0} + {"deficon", &deficon, "Default icon name", NULL, ARGTYPE_STRING }, + {0, 0, 0, 0, 0} }; static void @@ -1391,6 +1392,7 @@ ff_vecs_t mag_svecs = { mag_deinit, mag_read, mag_write, + NULL, mag_sargs }; @@ -1402,5 +1404,6 @@ ff_vecs_t mag_fvecs = { mag_deinit, mag_read, mag_write, + NULL, mag_fargs }; diff --git a/gpsbabel/mapsource.c b/gpsbabel/mapsource.c index 889905c9f..d303814ac 100644 --- a/gpsbabel/mapsource.c +++ b/gpsbabel/mapsource.c @@ -65,23 +65,30 @@ static void *read_route_wpt_mkshort_handle; #define MPSNOTESBUFFERLEN 4096 #define MPSDESCBUFFERLEN 4096 -char *snlen; -char *snwhiteopt; -char *mpsverout; +char *snlen = NULL; +char *snwhiteopt = NULL; +char *mpsverout = NULL; char *mpsmergeout = NULL; char *mpsusedepth = NULL; char *mpsuseprox = NULL; static arglist_t mps_args[] = { - {"snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT }, + {"snlen", &snlen, "Length of generated shortnames", NULL, ARGTYPE_INT }, { "snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames", - ARGTYPE_BOOL}, - {"mpsverout", &mpsverout, "Version of mapsource file to generate (3,4,5)", ARGTYPE_INT }, - {"mpsmergeout", &mpsmergeout, "Merge output with existing file", ARGTYPE_BOOL }, - {"mpsusedepth", &mpsusedepth, "Use depth values on output (default is ignore)", ARGTYPE_BOOL }, - {"mpsuseprox", &mpsuseprox, "Use proximity values on output (default is ignore)", ARGTYPE_BOOL }, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL}, + {"mpsverout", &mpsverout, + "Version of mapsource file to generate (3,4,5)", NULL, + ARGTYPE_INT }, + {"mpsmergeout", &mpsmergeout, "Merge output with existing file", + NULL, ARGTYPE_BOOL }, + {"mpsusedepth", &mpsusedepth, + "Use depth values on output (default is ignore)", NULL, + ARGTYPE_BOOL }, + {"mpsuseprox", &mpsuseprox, + "Use proximity values on output (default is ignore)", + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; /* @@ -2162,5 +2169,6 @@ ff_vecs_t mps_vecs = { mps_wr_deinit, mps_read, mps_write, + NULL, mps_args }; diff --git a/gpsbabel/navicache.c b/gpsbabel/navicache.c index bc825dfdb..0d42a38ba 100644 --- a/gpsbabel/navicache.c +++ b/gpsbabel/navicache.c @@ -27,13 +27,13 @@ static waypoint *wpt_tmp; FILE *fd; FILE *ofd; -static char *noretired; +static char *noretired = NULL; static arglist_t nav_args[] = { {"noretired", &noretired, "Suppress retired geocaches.", - ARGTYPE_BOOL }, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; #define MYNAME "navicache" @@ -262,5 +262,6 @@ ff_vecs_t navicache_vecs = { nav_wr_deinit, nav_read, nav_write, + NULL, nav_args, }; diff --git a/gpsbabel/netstumbler.c b/gpsbabel/netstumbler.c index 5f5dba9af..1674215e6 100644 --- a/gpsbabel/netstumbler.c +++ b/gpsbabel/netstumbler.c @@ -25,15 +25,11 @@ #include static FILE *file_in; -static char *nseicon = "Red Square"; -static char *nsneicon = "Green Square"; -static char *seicon = "Red Diamond"; -static char *sneicon = "Green Diamond"; +static char *nseicon = NULL; +static char *nsneicon = NULL; +static char *seicon = NULL; +static char *sneicon = NULL; static char *snmac = NULL; -static char *optnseicon = NULL; -static char *optnsneicon = NULL; -static char *optseicon = NULL; -static char *optsneicon = NULL; static void fix_netstumbler_dupes(void); @@ -41,21 +37,21 @@ static void fix_netstumbler_dupes(void); static arglist_t netstumbler_args[] = { - {"nseicon", &optnseicon, "Non-stealth encrypted icon name", ARGTYPE_STRING }, - {"nsneicon", &optnsneicon, "Non-stealth non-encrypted icon name", ARGTYPE_STRING }, - {"seicon", &optseicon, "Stealth encrypted icon name", ARGTYPE_STRING }, - {"sneicon", &optsneicon, "Stealth non-encrypted icon name", ARGTYPE_STRING }, - {"snmac", &snmac, "Shortname is MAC address", ARGTYPE_BOOL }, - {0, 0, 0, 0} + {"nseicon", &nseicon, "Non-stealth encrypted icon name", + "Red Square", ARGTYPE_STRING }, + {"nsneicon", &nsneicon, "Non-stealth non-encrypted icon name", + "Green Square", ARGTYPE_STRING }, + {"seicon", &seicon, "Stealth encrypted icon name", + "Red Diamond", ARGTYPE_STRING }, + {"sneicon", &sneicon, "Stealth non-encrypted icon name", + "Green Diamond", ARGTYPE_STRING }, + {"snmac", &snmac, "Shortname is MAC address", NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; static void rd_init(const char *fname) { - nseicon = optnseicon?optnseicon:"Red Square"; - nsneicon = optnsneicon?optnsneicon:"Green Square"; - seicon = optseicon?optseicon:"Red Diamond"; - sneicon = optsneicon?optsneicon:"Green Diamond"; file_in = xfopen(fname, "r", MYNAME); } @@ -303,5 +299,6 @@ ff_vecs_t netstumbler_vecs = { NULL, data_read, NULL, + NULL, netstumbler_args }; diff --git a/gpsbabel/ozi.c b/gpsbabel/ozi.c index cf9915c53..ff9487571 100644 --- a/gpsbabel/ozi.c +++ b/gpsbabel/ozi.c @@ -40,22 +40,22 @@ static int track_out_count; static int route_out_count; static int route_wpt_count; -static char *snlenopt; -static char *snwhiteopt; -static char *snupperopt; -static char *snuniqueopt; +static char *snlenopt = NULL; +static char *snwhiteopt = NULL; +static char *snupperopt = NULL; +static char *snuniqueopt = NULL; static arglist_t ozi_args[] = { {"snlen", &snlenopt, "Max synthesized shortname length", - ARGTYPE_INT}, + NULL, ARGTYPE_INT}, {"snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"snupper", &snupperopt, "(0/1) UPPERCASE synth. shortnames", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"snunique", &snuniqueopt, "(0/1) Make synth. shortnames unique", - ARGTYPE_BOOL}, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL}, + {0, 0, 0, 0, 0} }; gpsdata_type ozi_objective; @@ -698,5 +698,6 @@ ff_vecs_t ozi_vecs = { wr_deinit, data_read, data_write, + NULL, ozi_args }; diff --git a/gpsbabel/palmdoc.c b/gpsbabel/palmdoc.c index f456e3489..40cf79b00 100644 --- a/gpsbabel/palmdoc.c +++ b/gpsbabel/palmdoc.c @@ -67,14 +67,16 @@ struct buffer { static arglist_t palmdoc_args[] = { { "nosep", &suppresssep, - "Suppress separator lines between waypoints", ARGTYPE_BOOL }, - {"dbname", &dbname, "Database name", ARGTYPE_STRING }, - {"encrypt", &encrypt, "Encrypt hints with ROT13", ARGTYPE_BOOL }, + "Suppress separator lines between waypoints", NULL, + ARGTYPE_BOOL }, + {"dbname", &dbname, "Database name", NULL, ARGTYPE_STRING }, + {"encrypt", &encrypt, "Encrypt hints with ROT13", NULL, + ARGTYPE_BOOL }, { "logs", &includelogs, - "Include groundspeak logs if present", ARGTYPE_BOOL }, + "Include groundspeak logs if present", NULL, ARGTYPE_BOOL }, { "bookmarks_short", &bmid, "Include short name in bookmarks", - ARGTYPE_BOOL }, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; static struct buffer buf; @@ -608,6 +610,7 @@ ff_vecs_t palmdoc_vecs = { wr_deinit, NULL, data_write, + NULL, palmdoc_args }; diff --git a/gpsbabel/pcx.c b/gpsbabel/pcx.c index 6ac56afad..4b4997b6d 100644 --- a/gpsbabel/pcx.c +++ b/gpsbabel/pcx.c @@ -26,26 +26,20 @@ static FILE *file_in; static FILE *file_out; static void *mkshort_handle; -static char *optdeficon = NULL; -static char *deficon = "Waypoint"; +static char *deficon = NULL; #define MYNAME "PCX" static arglist_t pcx_args[] = { - {"deficon", &optdeficon, "Default icon name", ARGTYPE_STRING }, - {0, 0, 0, 0} + {"deficon", &deficon, "Default icon name", "Waypoint", + ARGTYPE_STRING }, + {0, 0, 0, 0, 0} }; static void rd_init(const char *fname) { - if ( optdeficon ) { - deficon = optdeficon; - } - else { - deficon = "Waypoint"; - } file_in = xfopen(fname, "r", MYNAME); } @@ -58,12 +52,6 @@ rd_deinit(void) static void wr_init(const char *fname) { - if ( optdeficon ) { - deficon = optdeficon; - } - else { - deficon = "Waypoint"; - } file_out = xfopen(fname, "w", MYNAME); mkshort_handle = mkshort_new_handle(); } @@ -284,5 +272,6 @@ ff_vecs_t pcx_vecs = { wr_deinit, data_read, data_write, + NULL, pcx_args }; diff --git a/gpsbabel/polygon.c b/gpsbabel/polygon.c index fd7850c6a..174eec4c6 100644 --- a/gpsbabel/polygon.c +++ b/gpsbabel/polygon.c @@ -44,10 +44,10 @@ typedef struct { static arglist_t polygon_args[] = { {"file", &polyfileopt, "File containing vertices of polygon", - ARGTYPE_FILE | ARGTYPE_REQUIRED }, + NULL, ARGTYPE_FILE | ARGTYPE_REQUIRED }, {"exclude", &exclopt, "Exclude points inside the polygon", - ARGTYPE_BOOL }, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; static void polytest ( double lat1, double lon1, diff --git a/gpsbabel/position.c b/gpsbabel/position.c index b7d6e3dca..9105dfff0 100644 --- a/gpsbabel/position.c +++ b/gpsbabel/position.c @@ -29,12 +29,12 @@ extern queue waypt_head; static route_head *cur_rte = NULL; static double pos_dist; -static char *distopt; +static char *distopt = NULL; static char *purge_duplicates = NULL; -static char *latopt; -static char *lonopt; -static char *exclopt; -static char *nosort; +static char *latopt = NULL; +static char *lonopt = NULL; +static char *exclopt = NULL; +static char *nosort = NULL; waypoint * home_pos; @@ -45,24 +45,26 @@ typedef struct { static arglist_t position_args[] = { {"distance", &distopt, "Maximum positional distance", - ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, - {"all", &purge_duplicates, "Suppress all points close to other points", ARGTYPE_BOOL }, - {0, 0, 0, 0} + NULL, ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + {"all", &purge_duplicates, + "Suppress all points close to other points", + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; static arglist_t radius_args[] = { {"lat", &latopt, "Latitude for center point (D.DDDDD)", - ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + NULL, ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, {"lon", &lonopt, "Longitude for center point (D.DDDDD)", - ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + NULL, ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, {"distance", &distopt, "Maximum distance from center", - ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + NULL, ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, {"exclude", &exclopt, "Exclude points close to center", - ARGTYPE_BOOL }, + NULL, ARGTYPE_BOOL }, {"nosort", &nosort, "Inhibit sort by distance to center.", - ARGTYPE_BOOL }, - {0, 0, 0, 0} + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; static double diff --git a/gpsbabel/psitrex.c b/gpsbabel/psitrex.c index 00336f1ef..9166f830f 100755 --- a/gpsbabel/psitrex.c +++ b/gpsbabel/psitrex.c @@ -56,8 +56,9 @@ char *snlen; static arglist_t psit_args[] = { -/* {"snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT }, */ - {0, 0, 0, 0} +/* {"snlen", &snlen, "Length of generated shortnames", + NULL, ARGTYPE_INT }, */ + {0, 0, 0, 0, 0} }; /* Taken from PsiTrex 1.13 */ @@ -804,5 +805,6 @@ ff_vecs_t psit_vecs = { psit_wr_deinit, psit_read, psit_write, + NULL, psit_args }; diff --git a/gpsbabel/quovadis.c b/gpsbabel/quovadis.c index 9a2546f19..a5274f801 100644 --- a/gpsbabel/quovadis.c +++ b/gpsbabel/quovadis.c @@ -35,8 +35,8 @@ static char *dbname = NULL; static arglist_t quovadis_args[] = { - {"dbname", &dbname, "Database name", ARGTYPE_STRING}, - {0, 0, 0, 0} + {"dbname", &dbname, "Database name", NULL, ARGTYPE_STRING}, + {0, 0, 0, 0, 0} }; static struct qv_icon_mapping mapping[] = { @@ -291,5 +291,6 @@ ff_vecs_t quovadis_vecs = { wr_deinit, data_read, data_write, + NULL, quovadis_args }; diff --git a/gpsbabel/reverse_route.c b/gpsbabel/reverse_route.c index 336537251..9589c7450 100644 --- a/gpsbabel/reverse_route.c +++ b/gpsbabel/reverse_route.c @@ -25,7 +25,7 @@ static arglist_t reverse_route_args[] = { - {0, 0, 0, 0} + {0, 0, 0, 0, 0} }; void diff --git a/gpsbabel/saroute.c b/gpsbabel/saroute.c index 00e44a444..23152112e 100644 --- a/gpsbabel/saroute.c +++ b/gpsbabel/saroute.c @@ -34,9 +34,10 @@ char *turns_only = NULL; static arglist_t saroute_args[] = { {"turns_important", &turns_important, - "Keep turns if simplify filter is used", ARGTYPE_BOOL }, + "Keep turns if simplify filter is used", + NULL, ARGTYPE_BOOL }, {"turns_only", &turns_only, "Only read turns; skip all other points", - ARGTYPE_BOOL }, + NULL, ARGTYPE_BOOL }, {0, 0, 0, 0 } }; @@ -275,5 +276,6 @@ ff_vecs_t saroute_vecs = { NULL, my_read, NULL, + NULL, saroute_args }; diff --git a/gpsbabel/smplrout.c b/gpsbabel/smplrout.c index 3c3b0a17b..da2145635 100644 --- a/gpsbabel/smplrout.c +++ b/gpsbabel/smplrout.c @@ -30,8 +30,8 @@ static char *countopt = NULL; static arglist_t routesimple_args[] = { {"count", &countopt, "Maximum number of points in route", - ARGTYPE_INT | ARGTYPE_REQUIRED}, - {0, 0, 0, 0} + NULL, ARGTYPE_INT | ARGTYPE_REQUIRED}, + {0, 0, 0, 0, 0} }; struct xte_intermed; diff --git a/gpsbabel/sort.c b/gpsbabel/sort.c index c773e65eb..e91af8317 100644 --- a/gpsbabel/sort.c +++ b/gpsbabel/sort.c @@ -35,10 +35,13 @@ static char *opt_sm_gcid, *opt_sm_shortname, *opt_sm_description; static arglist_t sort_args[] = { - {"gcid", &opt_sm_gcid, "Sort by numeric geocache ID", ARGTYPE_BOOL }, - {"shortname", &opt_sm_shortname, "Sort by waypoint short name", ARGTYPE_BOOL }, - {"description", &opt_sm_description, "Sort by waypoint description", ARGTYPE_BOOL }, - {0, 0, 0, 0} + {"gcid", &opt_sm_gcid, "Sort by numeric geocache ID", + NULL, ARGTYPE_BOOL }, + {"shortname", &opt_sm_shortname, "Sort by waypoint short name", + NULL, ARGTYPE_BOOL }, + {"description", &opt_sm_description, "Sort by waypoint description", + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; static int diff --git a/gpsbabel/stackfilter.c b/gpsbabel/stackfilter.c index 963e7572a..d581bbb52 100644 --- a/gpsbabel/stackfilter.c +++ b/gpsbabel/stackfilter.c @@ -37,15 +37,22 @@ static int swapdepth = 0; static arglist_t stackfilt_args[] = { - {"push", &opt_push, "Push waypoint list onto stack", ARGTYPE_BOOL}, - {"copy", &opt_copy, "Copy waypoint list when pushing", ARGTYPE_BOOL}, - {"pop", &opt_pop, "Pop waypoint list from stack", ARGTYPE_BOOL}, - {"append", &opt_append, "Append list when popping", ARGTYPE_BOOL}, - {"discard", &opt_discard, "Discard top of stack when popping", ARGTYPE_BOOL}, - {"replace", &opt_replace, "Replace list with top of stack (default)", ARGTYPE_BOOL}, - {"swap", &opt_swap, "Swap waypoint list with item on stack", ARGTYPE_BOOL}, - {"depth", &opt_depth, "Item to use when swapping", ARGTYPE_INT}, - {0, 0, 0, 0} + {"push", &opt_push, "Push waypoint list onto stack", NULL, + ARGTYPE_BOOL}, + {"copy", &opt_copy, "Copy waypoint list when pushing", NULL, + ARGTYPE_BOOL}, + {"pop", &opt_pop, "Pop waypoint list from stack", NULL, + ARGTYPE_BOOL}, + {"append", &opt_append, "Append list when popping", NULL, + ARGTYPE_BOOL}, + {"discard", &opt_discard, "Discard top of stack when popping", + NULL, ARGTYPE_BOOL}, + {"replace", &opt_replace, "Replace list with top of stack (default)", + NULL, ARGTYPE_BOOL}, + {"swap", &opt_swap, "Swap waypoint list with item on stack", + NULL, ARGTYPE_BOOL}, + {"depth", &opt_depth, "Item to use when swapping", NULL, ARGTYPE_INT}, + {0, 0, 0, 0, 0} }; struct stack_elt { diff --git a/gpsbabel/text.c b/gpsbabel/text.c index d21a42413..b369e7500 100644 --- a/gpsbabel/text.c +++ b/gpsbabel/text.c @@ -36,12 +36,13 @@ static char *includelogs = NULL; static arglist_t text_args[] = { { "nosep", &suppresssep, - "Suppress separator lines between waypoints", ARGTYPE_BOOL }, + "Suppress separator lines between waypoints", + NULL, ARGTYPE_BOOL }, { "encrypt", &encrypt, - "Encrypt hints using ROT13", ARGTYPE_BOOL }, + "Encrypt hints using ROT13", NULL, ARGTYPE_BOOL }, { "logs", &includelogs, - "Include groundspeak logs if present", ARGTYPE_BOOL }, - {0, 0, 0, 0} + "Include groundspeak logs if present", NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; @@ -225,5 +226,6 @@ ff_vecs_t text_vecs = { wr_deinit, NULL, data_write, + NULL, text_args }; diff --git a/gpsbabel/tiger.c b/gpsbabel/tiger.c index b717f65bd..e0fdfd4f1 100644 --- a/gpsbabel/tiger.c +++ b/gpsbabel/tiger.c @@ -37,21 +37,13 @@ static char *suppresswhite = NULL; static char *iconismarker = NULL; static char *snlen = NULL; -static char *margin = "15%"; -static char *xpixels = "768"; -static char *ypixels = "768"; -static char *oldthresh = "14"; -static char *oldmarker = "redpin"; -static char *newmarker = "greenpin"; -static char *unfoundmarker = "bluepin"; - -static char *optmargin = NULL; -static char *optxpixels = NULL; -static char *optypixels = NULL; -static char *optoldthresh = NULL; -static char *optoldmarker = NULL; -static char *optnewmarker = NULL; -static char *optunfoundmarker = NULL; +static char *margin = NULL; +static char *xpixels = NULL; +static char *ypixels = NULL; +static char *oldthresh = NULL; +static char *oldmarker = NULL; +static char *newmarker = NULL; +static char *unfoundmarker = NULL; int scalev; int short_length; @@ -71,47 +63,43 @@ static char *clickmap = NULL; static arglist_t tiger_args[] = { {"nolabels", &nolabels, "Suppress labels on generated pins.", - ARGTYPE_BOOL }, + NULL, ARGTYPE_BOOL }, {"genurl", &genurl, "Generate file with lat/lon for centering map.", - ARGTYPE_OUTFILE }, - {"margin", &optmargin, "Margin for map. Degrees or percentage.", - ARGTYPE_FLOAT}, + NULL, ARGTYPE_OUTFILE }, + {"margin", &margin, "Margin for map. Degrees or percentage.", + "15%", ARGTYPE_FLOAT}, {"snlen", &snlen, "Max shortname length when used with -s.", - ARGTYPE_INT}, - {"oldthresh", &optoldthresh, "Days after which points are considered old.", - ARGTYPE_INT}, - {"oldmarker", &optoldmarker, "Marker type for old points.", - ARGTYPE_STRING}, - {"newmarker", &optnewmarker, "Marker type for new points.", - ARGTYPE_STRING}, + NULL, ARGTYPE_INT}, + {"oldthresh", &oldthresh, + "Days after which points are considered old.", + "14", ARGTYPE_INT}, + {"oldmarker", &oldmarker, "Marker type for old points.", + "redpin", ARGTYPE_STRING}, + {"newmarker", &newmarker, "Marker type for new points.", + "greenpin", ARGTYPE_STRING}, {"suppresswhite", &suppresswhite, - "Suppress whitespace in generated shortnames", ARGTYPE_BOOL }, - {"unfoundmarker", &optunfoundmarker, "Marker type for unfound points.", - ARGTYPE_STRING}, - {"xpixels", &optxpixels, "Width in pixels of map.", - ARGTYPE_INT}, - {"ypixels", &optypixels, "Height in pixels of map.", - ARGTYPE_INT}, + "Suppress whitespace in generated shortnames", + NULL, ARGTYPE_BOOL }, + {"unfoundmarker", &unfoundmarker, "Marker type for unfound points.", + "bluepin", ARGTYPE_STRING}, + {"xpixels", &xpixels, "Width in pixels of map.", + "768", ARGTYPE_INT}, + {"ypixels", &ypixels, "Height in pixels of map.", + "768", ARGTYPE_INT}, {"iconismarker", &iconismarker, - "The icon description is already the marker", ARGTYPE_BOOL }, + "The icon description is already the marker", NULL, + ARGTYPE_BOOL }, #if CLICKMAP {"clickmap", &clickmap, "Generate Clickable map web page.", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, #endif - {0, 0, 0, 0} + {0, 0, 0, 0, 0} }; static void rd_init(const char *fname) { - margin = optmargin?optmargin:"15%"; - xpixels = optxpixels?optxpixels:"768"; - ypixels = optypixels?optypixels:"768"; - oldthresh = optoldthresh?optoldthresh:"14"; - oldmarker = optoldmarker?optoldmarker:"redpin"; - newmarker = optnewmarker?optnewmarker:"greenpin"; - unfoundmarker = optunfoundmarker?optunfoundmarker:"bluepin"; file_in = xfopen(fname, "r", MYNAME); mkshort_handle = mkshort_new_handle(); } @@ -126,13 +114,6 @@ rd_deinit(void) static void wr_init(const char *fname) { - margin = optmargin?optmargin:"15%"; - xpixels = optxpixels?optxpixels:"768"; - ypixels = optypixels?optypixels:"768"; - oldthresh = optoldthresh?optoldthresh:"14"; - oldmarker = optoldmarker?optoldmarker:"redpin"; - newmarker = optnewmarker?optnewmarker:"greenpin"; - unfoundmarker = optunfoundmarker?optunfoundmarker:"bluepin"; file_out = xfopen(fname, "w", MYNAME); thresh_days = strtod(oldthresh, NULL); } @@ -302,5 +283,6 @@ ff_vecs_t tiger_vecs = { wr_deinit, data_read, data_write, + NULL, tiger_args, }; diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index c66f92b73..3fab6bbee 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -307,6 +307,9 @@ exit_vecs( void ) vecs_t *vec = vec_list; while ( vec->vec ) { arglist_t *ap; + if ( vec->vec->exit ) { + (*vec->vec->exit)(); + } if ( vec->vec->args ) { for ( ap = vec->vec->args; ap->argstring; ap++ ) { if ( ap->argval && *ap->argval ) { @@ -342,12 +345,37 @@ find_vec(char *const vecname, char **opts) if (vec->vec->args) { for (ap = vec->vec->args; ap->argstring; ap++){ + char *opt = NULL; if ( *ap->argval ) xfree(*ap->argval); - *ap->argval = get_option(*opts, ap->argstring); + + opt = get_option(*opts, ap->argstring); + if ( opt ) { + *ap->argval = opt; + } + else if ( ap->defaultvalue ) { + *ap->argval = xstrdup( + ap->defaultvalue ); + } + else { + *ap->argval = NULL; + } } } } else { *opts = NULL; + if (vec->vec->args) { + for (ap = vec->vec->args; ap->argstring; ap++){ + if ( *ap->argval ) xfree(*ap->argval); + + if ( ap->defaultvalue ) { + *ap->argval = xstrdup( + ap->defaultvalue ); + } + else { + *ap->argval = NULL; + } + } + } } xfree(v); diff --git a/gpsbabel/xcsv.c b/gpsbabel/xcsv.c index 3ffb50efa..fe22c83dc 100644 --- a/gpsbabel/xcsv.c +++ b/gpsbabel/xcsv.c @@ -30,31 +30,32 @@ #define MYNAME "XCSV" #define ISSTOKEN(a,b) (strncmp(a,b, strlen(b)) == 0) -static char *styleopt; -static char *snlenopt; -static char *snwhiteopt; -static char *snupperopt; -static char *snuniqueopt; -char *prefer_shortnames; -char *xcsv_urlbase; +static char *styleopt = NULL; +static char *snlenopt = NULL; +static char *snwhiteopt = NULL; +static char *snupperopt = NULL; +static char *snuniqueopt = NULL; +char *prefer_shortnames = NULL; +char *xcsv_urlbase = NULL; static arglist_t xcsv_args[] = { - {"style", &styleopt, "Full path to XCSV style file", + {"style", &styleopt, "Full path to XCSV style file", NULL, ARGTYPE_FILE | ARGTYPE_REQUIRED }, - {"snlen", &snlenopt, "Max synthesized shortname length", + {"snlen", &snlenopt, "Max synthesized shortname length", NULL, ARGTYPE_INT}, {"snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"snupper", &snupperopt, "(0/1) UPPERCASE synth. shortnames", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"snunique", &snuniqueopt, "(0/1) Make synth. shortnames unique", - ARGTYPE_BOOL}, + NULL, ARGTYPE_BOOL}, {"urlbase", &xcsv_urlbase, "Basename prepended to URL on output", - ARGTYPE_STRING}, + NULL, ARGTYPE_STRING}, {"prefer_shortnames", &prefer_shortnames, - "Use shortname instead of description", ARGTYPE_BOOL }, - {0, 0, 0, 0} + "Use shortname instead of description", + NULL, ARGTYPE_BOOL }, + {0, 0, 0, 0, 0} }; /* a table of config file constants mapped to chars */ @@ -542,5 +543,6 @@ ff_vecs_t xcsv_vecs = { xcsv_wr_deinit, xcsv_data_read, xcsv_data_write, + NULL, xcsv_args }; -- 2.30.2